(function(window, undefined) {
	var 
	isCheck = false, selectedStore = [], user_id = sessionStorage.getItem('user_id'),
	slidePageNumber = 0, MAX_OF_UNIT = 3;
	
	var Cast = {},
	indexPage = Cast.indexPage = {}, /*index.php*/
	writePage = Cast.writePage = {}, /*cast_write.php*/
	mainPage = Cast.mainPage = {}, /*cast.php*/
	castViewPage = Cast.castViewPage = {}, /*cast_view.php*/
	myCastPage = Cast.myCastPage = {}; /*mycast.php*/
	storeCastPage = Cast.storeCastPage = {}; /*store_view.php*/
	
	window.Cast = window.Cast || Cast;
	
	Cast.hotcastBlock = function() {
		var info = '<a href="#">XIILAB 화이팅</a>', info2 = '<a href="#">가로수길 디저트카페의 진리!</a>';
		$('div.hotCast').slideUp('slow', function() {
			if (!isCheck) {
				$('div.hotCast').html(info).show();
				isCheck = true;
			} else {
				$('div.hotCast').html(info2).show();
				isCheck = false;
			}
		});
	};
	storeCastPage.storeCastBlock = function(){
		var _store_id = checkUrlId();
		
		$.ajax({
			type : "post",
			url : ajaxURL + "cast.php?action=loadStoreCastList",
			data : {store_id:_store_id},
			dataType : "json",
			success : function(result) {
				console.log('storeCastBlock');
				console.log(result);
				if(result.length==0){
					_selector = '.rankingList';
					$(_selector).empty();
					template.noSideCast(_selector);
					$('.widgetNoneWrap').css("border","none");
				}else{
					_selector = '.rankingList li';
					$(_selector).empty();
					$(_selector).prepend('<div class="titleWrap"><a class="title" href="cast_view.php?id='+result.data[0].cast_id+'">'+result.data[0].name+'</a></div>');
					var list_length;
					if(result.data[0].store_id3==''||result.data[0].store_id3==null||result.data[0].store_id3==0){
						list_length=2;
					}else{
						list_length=3;
					}
					for(var key=0;key<list_length;key++){
						template.sideCastList(result.data[0], _selector,key);
					}
					$(_selector).append('<div class="bottomWrap"><a class="name">'+result.data[0].user_name+'</a><span class="recommend">유용해요 <b>'+result.data[0].useful_cast_count+'</b>명</span><span class="date right" >'+result.data[0].created_date.split(' ')[0]+'</span><div class="clear"></div></div>');

				}
				
			}
		});
	};
	myCastPage.myCastList = function(){
		var _selector = '.castList';
		$(_selector).empty();
		loadMyCastList(function(result){
			console.log(result);
			if(result.length==0){
				template.noMyCast(_selector);
			}
			$.each(result.data, function(key) {
				template.listBlock(_selector, this, key);
			});
			
			/*마이 캐스트 카운트*/
			$('.countWrap > b').html(result.length);
			
			var _para = {
				dataLength : result.length,
				selector : '#pagination > ul',
				callback : function() {
					myCastPage.myCastList();
				}
			};
			Paging.innerAJAX(_para);
		});
	};
	var loadMyCastList = function(callback){
		var _user_id = sessionStorage.getItem('user_id');
		
		$.ajax({
			type : "post",
			url : ajaxURL + "cast.php?action=loadMyCastList",
			data : {user_id:_user_id,row:Paging.getCurrent()},
			dataType : "json",
			success : function(result) {
				callback(result);
			}
		});
	};
	
	/*메인*/
	castViewPage.mainCastblock = function(){
		// var _selector = '.w680 > section > ul:nth(0) > li';
		loadSelectedCast(function(result){
			console.log('mainCastblock');
				
			var _castMain = result['data'],
			_store_id1 = result['store_id1'],
			_store_id2 = result['store_id2'],
			_store_id3 = result['store_id3'],
			_store_id4 = result['store_id4'],
			_store_id5 = result['store_id5'];
			
			$('#main_info > a.title').html(_castMain.name);
			$('#main_info > .bottomWrap > .name').html(_castMain.user_name);
			$('#main_info > .bottomWrap > .date').html(_castMain.created_date);
			$('#main_info > .commentWrap').html(_castMain.description);
			$('#main_info .usefulWrap > b').html(_castMain.useful_cast_count);
			$('#main_info .usefulBtn').attr('data-cast_id',_castMain.cast_id);
			
			if(_castMain.is_useful){
				$('#main_info .usefulBtn').addClass('off');
			}
			
			$('ul.storeList:nth(1)').empty();
			if(_store_id1){
				template.mainStoreList(_store_id1,'ul.storeList:nth(1)',0);
			}
			if(_store_id2){
				template.mainStoreList(_store_id2,'ul.storeList:nth(1)',1);
			}
			if(_store_id3.store_id){
				template.mainStoreList(_store_id3,'ul.storeList:nth(1)',2);
			}
			if(_store_id4.store_id){
				template.mainStoreList(_store_id4,'ul.storeList:nth(1)',3);
			}
			if(_store_id5.store_id){
				template.mainStoreList(_store_id5,'ul.storeList:nth(1)',4);
			}
			
			
			/*유용해요*/
			$('#main_info .usefulBtn').off('click').on('click',function(event){
				event.preventDefault();
								
				var user_id = sessionStorage.getItem('user_id');				
				if (!user_id) {
					if (confirm('본 기능은 로그인이 필요한 기능입니다. 로그인하러 가시겠습니까?')) {
						location.href = 'login.php';
					}
					return;
				}	
					
				$(this).toggleClass('off');
				
				var _useful = $(this).parent().children('b').html();
				var _cast_id = $(this).data('cast_id');
				
				if ($(this).hasClass('off')) {
					addUsefulCast(_cast_id);
					_useful = parseInt(_useful) + 1;
				} else {
					delUsefulCast(_cast_id);
					_useful = parseInt(_useful) - 1;
				}

				$(this).parent().children('b').html(_useful); 

			});
		});
	};
	var addUsefulCast = function(cast_id){
		var _user_id = sessionStorage.getItem('user_id');
		
		$.ajax({
			type:"post",
			url:ajaxURL + "useful.php?action=addUsefulCast",
			data:{user_id:_user_id,post_id:cast_id},
			success:function(result){
				 console.log(result);
			}
		});
	};
	var delUsefulCast = function(cast_id){
		var _user_id = sessionStorage.getItem('user_id');
		
		$.ajax({
			type:"post",
			url:ajaxURL + "useful.php?action=delUsefulCast",
			data:{user_id:_user_id,post_id:cast_id},
			success:function(result){
				console.log(result);
			}
		});
	};
	castViewPage.storeCastBlock = function(){
	};
	/*result {data : cast 내용, store1 : store1의 정보, store2 : store2의 정보 ...}*/
	var loadSelectedCast = function(callback){
		var _cast_id = getUrlId();
		var _user_id = sessionStorage.getItem('user_id');
		
		$.ajax({
			type : "post",
			url : ajaxURL + "cast.php?action=loadSelectedCast",
			data : {cast_id:_cast_id,user_id:_user_id},
			dataType : "json",
			success : function(result) {
				callback(result);
			}
		});
	};
	
	mainPage.listBlock = function() {
		var _selector = 'ul.castList';
		loadCastList(function(result) {
			console.log('loadCastList');
			console.log(result);
			$(_selector).empty();
			$.each(result.data, function(key) {
				template.listBlock(_selector, this, key);
			});
			
			var _para = {
				dataLength : result.length,
				// dataLength : 13,
				selector : '#pagination > ul',
				callback : function() {
					mainPage.listBlock();
				}
			};
			Paging.innerAJAX(_para);
		});
	};
	var loadCastList = function(callback) {
		$.ajax({
			type : "post",
			url : ajaxURL + "cast.php?action=loadCastList",
			data : {row:Paging.getCurrent()},
			dataType : "json",
			success : function(result) {
				callback(result);
			}
		});
	};
	
	/*indexPage*/
	mainPage.slideBlock = indexPage.slideBlock =function() {
		var _selector = '.castWidgetWrap > ul';
		
		loadSlideCast(function(result) {
			$(_selector).empty();
			$.each(result, function(key) {
				template.slideBlock(_selector, this);
			});
			
			$('.castWidget').fadeIn();
		});
		/*캐스트 작성*/
		$('.castWidgetWrap > a.right').off('click').on('click', function(event) {
			event.preventDefault();
			
			var user_id = sessionStorage.getItem('user_id');
			if(!user_id){
				if(confirm('본 기능은 로그인이 필요한 기능입니다. 로그인하러 가시겠습니까?')){
					location.href='login.php';
				}
				return ;	
			}	
			location.href = "cast_write.php";
		});
		
		$('.castSlideControll > ul > li:nth(0)').off('click').on('click',function(event){
			event.preventDefault();
			
			$('.castWidget').fadeOut(270);
			
			slidePageNumber = 0;
			setTimeout("Cast.mainPage.slideBlock()",250);
			
			$('.castSlideControll > ul > li').removeClass('on');
			$(this).addClass('on');
		});
		
		$('.castSlideControll > ul > li:nth(1)').off('click').on('click',function(event){
			event.preventDefault();
			
			$('.castWidget').fadeOut(270);
			
			slidePageNumber = 1;
			setTimeout("Cast.mainPage.slideBlock()",250);
			
			$('.castSlideControll > ul > li').removeClass('on');
			$(this).addClass('on');
		});
		$('.castSlideControll > ul > li:nth(2)').off('click').on('click',function(event){
			event.preventDefault();
			
			$('.castWidget').fadeOut(270);
			
			slidePageNumber = 2;
			setTimeout("Cast.mainPage.slideBlock()",250);
			
			$('.castSlideControll > ul > li').removeClass('on');
			$(this).addClass('on');
		});
	};
	
	var loadSlideCast = function(callback) {
		$.ajax({
			type : "post",
			url : ajaxURL + "cast.php?action=loadSlideCast",
			data : {page_number:slidePageNumber*MAX_OF_UNIT},
			dataType : "json",
			success : function(result) {
				console.log('loadSlideCast');
				console.log(result);
				callback(result);
			}
		});
	};
	
	writePage.completeBlock = function() {
		/*작성완료*/
		$('div.buttonWrap > a').off('click').on('click', function(event) {
			event.preventDefault();
			var _title = $('table input:nth(0)').val(), _description = $('table textarea').val();
			if (_title == '') {
				alert('제목을 작성해주세요');
				return;
			}
			if (_description == '') {
				alert('내용을 작성해주세요');
				return;
			}
			if (!selectedStore[0]) {
				alert('스토어를 한개이상 선택하셔야합니다.');
				return;
			}
			addCast(_title, _description);
		});
	};
	
	var addCast = function(title, description) {
		var _user_id = sessionStorage.getItem('user_id');
		var _store_id1 = 0, _store_id2 = 0, _store_id3 = 0, _store_id4 = 0, _store_id5 = 0;
		if (selectedStore[0]) {
			_store_id1 = selectedStore[0].store_id;
		}
		if (selectedStore[1]) {
			_store_id2 = selectedStore[1].store_id;
		}
		if (selectedStore[2]) {
			_store_id3 = selectedStore[2].store_id;
		}
		if (selectedStore[3]) {
			_store_id4 = selectedStore[3].store_id;
		}
		if (selectedStore[4]) {
			_store_id5 = selectedStore[4].store_id;
		}
		$.ajax({
			type : 'post',
			url : ajaxURL + 'cast.php?action=addCast',
			data : {
				user_id : _user_id,
				name : title,
				description : description,
				store_id1 : _store_id1,
				store_id2 : _store_id2,
				store_id3 : _store_id3,
				store_id4 : _store_id4,
				store_id5 : _store_id5
			},
			success : function(result) {
				if (result == "success") {
					alert('등록되었습니다.');
					location.href = 'cast.php';
				}
			}
		});
	};
	writePage.selectedStoreBlock = function() {
		var _selector = 'ul.casteWriteStore';
		var _status = 'done';
		$(_selector).empty();
		for (var _index = 0; _index < 5; _index++) {
			if (!selectedStore[_index]) {
				template.noneNySelectedStore(_selector, _index);
			} else {
				template.mySelectedStore(_selector, selectedStore[_index], _index);
			}
		}
		/*스토어선택 > 위*/
		$('a.up').off('click').off('click').on('click', function(event) {
			event.preventDefault();
			
			var _index = $(this).parent().children('.delete').data('key'), _prevIndex = _index - 1, temp = null;
			if(_index < 1){
				alert('최상위 스토어 입니다.');
				return ;
			}
			
			$(this).parent().parent().css({"-webkit-transform": "translateY(-130px)","-webkit-transition-duration": "1000ms"}).children('.number').html(_prevIndex+1);
			$('.delete[data-key=' + _prevIndex + ']').parent().parent().css({"-webkit-transform": "translateY(130px)","-webkit-transition-duration": "1000ms"}).children('.number').html(_index + 1);
			
			/*swap*/
			temp = selectedStore[_index];
			selectedStore[_index] = selectedStore[_prevIndex];
			selectedStore[_prevIndex] = temp;
			
			$('a.up').off('click');
			setTimeout("Cast.writePage.selectedStoreBlock()",1000);
		});
		/*스토어선택 > 삭제*/
		$('a.delete').off('click').off('click').on('click', function(event) {
			event.preventDefault();
			
			delSelectedStore($(this).data('key'));
			writePage.selectedStoreBlock();
		});
		/*스토어선택 > 아래*/
		$('a.down').off('click').on('click', function(event) {
			event.preventDefault();
			
			var _index = $(this).parent().children('.delete').data('key'), _nextIndex = _index + 1, temp = null;
			
			if(_nextIndex >= selectedStore.length){
				alert('최하위 스토어 입니다.');
				return ;
			}
			
			$(this).parent().parent().css({"-webkit-transform": "translateY(130px)","-webkit-transition-duration": "1000ms"}).children('.number').html(_nextIndex+1);
			$('.delete[data-key=' + _nextIndex + ']').parent().parent().css({"-webkit-transform": "translateY(-130px)","-webkit-transition-duration": "1000ms"}).children('.number').html(_index + 1);
			
			/*swap*/
			temp = selectedStore[_index];
			selectedStore[_index] = selectedStore[_nextIndex];
			selectedStore[_nextIndex] = temp;
			
			$('a.down').off('click');
			setTimeout("Cast.writePage.selectedStoreBlock()",1000);
		});
	};
	writePage.mySideFavoriteStoreBlock = function() {
		/*딘골리스트 > init*/
		var _selector = 'ul.storeListWidget';
		$(_selector).empty();
		Store.loadMyStoreList(function(result) {
			console.log(result);
			$.each(result.data, function(key) {
				template.mySideFavoriteStore(_selector, this, key);
			});
			/*단골리스트 > 선택*/
			$('ul.storeListWidget > li > div.infoWrap > div.descWrap > a').off('click').on('click', function(event) {
				event.preventDefault();
				addSelectedStore(result.data[$(this).data('key')]);
				writePage.selectedStoreBlock();
				// $(this).parent().parent().parent().addClass('selected');
				// $(this).children('img').attr('src','images/btn_selected.png');
			});
		});
	};
	var addSelectedStore = function(data) {
		var _check = true;
		$.each(selectedStore, function() {
			if (this.store_id == data.store_id) {
				_check = false;
			}
		});
		if (_check) {
			selectedStore.push(data);
		} else {
			alert('이미 등록된 상점입니다.');
		}
	};
	var delSelectedStore = function(number) {
		selectedStore.splice(number, 1);
	};
	var template = {
		noMyCast : function(selector){
			var info = '';
			info += '<div class="noneListWrap">';
			info += '<div class="titleArea">';
			info += '<img src="images/nolist_cast.png" alt=""  />';
			info += '<h4>등록된 캐스트가 없습니다.</h4></div>';
			info += '<div class="subArea">';
			info += '<p>나만의 특색있는 캐스트를 작성해보세요.<br/><br/>';
			info += '<a href="cast_write.php"><img src="images/btn_cast_write.png" alt="캐스트작성" /></a>';
			info += '</p></div></div>';
			$(selector).append(info);
		},
		noSideCast : function(selector){
			var info = '';
			info += '<li class="first-child">';
			info += '<div class="widgetNoneWrap">';
			info += '<img src="images/nolist_talk_s.png" alt="nolist_coupon_s"   />';
			info += '<span>관련 캐스트가 없습니다.</span>';
			info += '</div>';
			info += '</li>';	
			
			$(selector).append(info);
		},
		/*케스트 리스트*/
		listBlock : function(selector, result, key) {
			if (!result.store_image1) {
				result.store_image1 = 'images/default_store.png';
			}
			if (!result.store_image2) {
				result.store_image2 = 'images/default_store.png';
			}
			if (!result.store_image3) {
				result.store_image3 = 'images/default_store.png';
			}
			if (!result.store_image4) {
				result.store_image4 = 'images/default_store.png';
			}
			if (!result.store_image5) {
				result.store_image5 = 'images/default_store.png';
			}
			var info = '';
			if (key == 0) {
				info += '<li class="first-child">';
			} else {
				info += '<li>';
			}
			info += '<div class="thumbWrap">';
			info += '<a href="#">';
			info += '<div class="wrap"><img class="img1" src="' + result.store_image1 + '" alt="thumb_store_1" style="width:160px;height:120px"><div class="pop"><span>' + result.store_name1 + '</span></div></div>';
			info += '<div class="wrap"><img src="' + result.store_image2 + '" alt="thumb_store_1" style="width:80px;height:59px"><div class="pop"><span>' + result.store_name2 + '</span></div></div>'
			info += '<div class="wrap"><img src="' + result.store_image3 + '" alt="thumb_store_1" style="width:80px;height:59px"><div class="pop"><span>' + result.store_name3 + '</span></div></div>';
			info += '<div class="wrap"><img src="' + result.store_image4 + '" alt="thumb_store_1" style="width:80px;height:59px"><div class="pop"><span>' + result.store_name4 + '</span></div></div>';
			info += '<div class="wrap"><img src="' + result.store_image5 + '" alt="thumb_store_1" style="width:80px;height:59px"><div class="pop"><span>' + result.store_name5 + '</span></div></div>';
			info += '</a>';
			info += '</div>';
			info += '<div class="infoWrap">';
			info += '<a class="title" href="cast_view.php?id='+result.cast_id+'">' + result.name + '</a>';
			info += '<div class="bottomWrap">';
			info += '<a class="name">' + result.user_name + '</a>님의 캐스트';
			info += '<span class="recommend">유용해요 <b>'+result.useful_cast_count+'</b>명</span>';
			info += '<span class="date right">' + result.created_date.split(' ')[0] + '</span>';
			info += '<div class="clear"></div>';
			info += '</div>';
			info += '</div>';
			info += '</li>';
			$(selector).append(info);
		},
		/*단골 리스트*/
		mySideFavoriteStore : function(selector, result, key) {
			if (!result.store_image) {
				result.store_image = 'images/default_store.png';
			}
			var info = '';
			if (key == 0) {
				info += '<li class="first-child"">';
			} else {
				info += '<li>';
			}
			info += '<div class="thumbWrap">';
			info += '<a href="#">';
			info += '<img src="' + result.store_image + '" alt="thumb_store_1">';
			info += '</a>';
			info += '</div>';
			info += '<div class="infoWrap">';
			info += '<a class="title" href="#">' + result.name + '</a>';
			info += '<div class="descWrap">';
			info += '<div class="tags">' + result.category_name + ' <span>|</span> ' + result.addr2 + '</div><a data-key="' + key + '" href="#" class="right"><img src="images/btn_select.png" alt="btn_select"></a>';
			info += '<div class="clear"></div>';
			info += '</div>';
			info += '</div>';
			info += '</li>';
			$(selector).append(info);
		},
		noneNySelectedStore : function(selector, key) {
			var info = '';
			info += '<li class="dim">';
			info += '<div class="number">' + parseInt(key + 1) + '</div>';
			info += '<div class="guideText">우측 단골리스트에서 스토어를 선택해주세요.</div>';
			info += '<div class="clear"></div>';
			info += '</li>';
			$(selector).append(info);
		},
		mySelectedStore : function(selector, result, key) {
			if (!result.store_image) {
				result.store_image = 'images/default_store.png';
			}
			if (!result.user_image) {
				result.user_image = 'images/default_user.png';
			}
			var info = '';
			info += '<li class="done">';
			info += '<div class="number">' + parseInt(key + 1) + '</div>';
			info += '<div class="thumbWrap">';
			info += '<a href="store_view.php?id='+result.store_id+'">';
			info += '<img src="' + result.store_image + '" alt="thumb_store_1" style="width:120px;height:90px;">';
			info += '</a>';
			info += '</div>';
			info += '<div class="infoWrap">';
			info += '<div class="store"><a href="store_view.php">' + result.name + '</a></div>';
			info += '<div class="tags">' + result.category_name + ' <span>|</span> ' + result.addr2 + '</div>';
			info += '<div class="values">';
			info += '단골 <b>' + result.favorite_count + '</b>명&nbsp;&nbsp;&nbsp;&nbsp;만족도 <b>' + result.satisfaction + '%</b>&nbsp;&nbsp;&nbsp;&nbsp;리뷰 <b>' + result.talk_count + '</b>개';
			info += '</div>';
			info += '</div>';
			info += '<div class="controller">';
			info += '<a class="up"><img src="images/btn_cast_up.png" alt="위로"></a>';
			info += '<a data-key="' + key + '" class="delete"><img src="images/btn_cast_delete.png" alt="삭제"></a>';
			info += '<a class="down"><img src="images/btn_cast_down.png" alt="아래로"></a>';
			info += '</div>';
			info += '<div class="clear"></div>';
			info += '</li>';
			$(selector).append(info);
		},
		slideBlock : function(selector, result) {
			if (!result.store_image) {
				result.store_image = 'images/default_store.png';
			}
			if (!result.user_image) {
				result.user_image = 'images/default_user.png';
			}
			var info = '';
			info += '<li class="first-child">';
			info += '<div class="thumbWrap">';
			info += '<a href="cast_view.php?id='+result.cast_id+'">';
			info += '<img src="' + result.store_image + '" alt="thumb_store_1" / style="width:280px;height:210px">';
			info += '</a>';
			info += '</div>';
			info += '<div class="infoWrap">';
			info += '<div class="user"><a href="#">' + result.user_name + '</a>님의 캐스트</div>';
			info += '<a class="title" href="cast_view.php?id='+result.cast_id+'">' + result.name + '</a>';
			info += '<div class="userThumb"><img src="' + result.user_image + '" alt="" style="width:60px;height:60px;"></div>';
			info += '</div>';
			info += '</li>';
			$(selector).append(info);
		},
		mainStoreList : function(result,selector,key){
			if(result.store_image==''){
				result.store_image='images/default_store.png';
			}
			
			var info='';
			if(key==0){
				info += '<li class="first-child bestStore" ><div class="thumbWrap">';
				info += '<a data-store_id="'+result.store_id+'" href="store_view.php?id='+result.store_id+'">';
				info += '<img src="'+result.store_image+'" width="280px" height="210px"  alt="thumb_store_1" />';
				info += '</a>'	;
				info += '</div>';
				info += '<span class="ranking rank1">'+(key+1)+'</span>';
			}else{
				info += '<li '+key+'><div class="thumbWrap">';
				info += '<a data-store_id="'+result.store_id+'" href="store_view.php?id='+result.store_id+'">';
				info += '<img src="'+result.store_image+'" width="160px" height="120px" alt="thumb_store_1" />';

				info += '</a>'	;
				info += '</div>';
				info += '<span class="ranking">'+(key+1)+'</span>';
			}
			info += '<div class="infoWrap">';	
			info += '<a data-store_id="'+result.store_id+'" class="title" href="store_view.php?id='+result.store_id+'">'+result.name+' </a>'	;		 
			info += '<div class="tags">'+result.category_name+' <span>|</span> '+result.addr2+'</div>';
			info += '<div class="values">만족도 <b>'+result.satisfaction+'%</b>&nbsp;&nbsp;&nbsp;&nbsp;구피토크 <b>'+result.talk_count+'</b>개</div>';
            
            info += '<div data-store_id="'+result.store_id+'" class="friends">';
            info += '</div>';
             
            info += '<div class="favorites">';
            info += '<span class="weekly"> <b>'+result.favoriteCountInWeek+'</b>명</span><br>';
            info += '<span class="total"> <b>'+result.favorite_count+'</b>명</span>';
            info += '</div></div>';
            info += '<div class="clear"></div></li>';
			$(selector).append(info);
		},
		sideCastList : function(result,selector,key){
			var store_id,store_name,store_image,store_addr,category_name,is_coupon;
			if(key==0){key='first';store_id=result.store_id1;store_name=result.store_name1;store_image=result.store_image1;store_addr=result.store_addr1;category_name=result.category_name1;is_coupon=result.is_coupon1;}
			else if(key==1){key='second';store_id=result.store_id2;store_name=result.store_name2;store_image=result.store_image2;store_addr=result.store_addr2;category_name=result.category_name2;is_coupon=result.is_coupon2;}
			else if(key==2){key='third';store_id=result.store_id3;store_name=result.store_name3;store_image=result.store_image3;store_addr=result.store_addr3;category_name=result.category_name3;is_coupon=result.is_coupon3;}
			
			if(store_image==''){
				store_image='images/default_store.png';
			}
			var info='';
	        info += '<div class="rankings '+key+'-child">';
			info += '<div class="thumbWrap">';
			info += '<a href="cast_view.php?id='+result.cast_id+'">';
			info += '<img height="48px" src="'+store_image+'" alt="thumb_store_1" />';
			info += '</a></div>';
			info += '<span class="rank"></span>';
			info += '<div class="infoWrap">';
			info += '<a class="title" href="cast_view.php?id='+result.cast_id+'">'+store_name;
			if(is_coupon==TRUE){
				info+='<img src="images/icon_coupon_s.png" alt="쿠폰" />';
			}
			info += '</a>';
			info += '<div class="tags">'+category_name+' <span>|</span> '+store_addr+'</div>';
			info += '</div></div>';
	        $(selector).append(info);
		}
	};
})(window); 